home *** CD-ROM | disk | FTP | other *** search
- //--------------------------------------------------------------------------
- //
- // Copyright (c) 2002, Colin Granville
- //
- // All rights reserved.
- //
- // Redistribution and use in source and binary forms, with or
- // without modification, are permitted provided that the following
- // conditions are met:
- //
- // * Redistributions of source code must retain the above copyright
- // notice, this list of conditions and the following disclaimer.
- //
- // * Redistributions in binary form must reproduce the above
- // copyright notice, this list of conditions and the following
- // disclaimer in the documentation and/or other materials
- // provided with the distribution.
- //
- // * The name Colin Granville may not be used to endorse or promote
- // products derived from this software without specific prior
- // written permission.
- //
- // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- // COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
- // OF THE POSSIBILITY OF SUCH DAMAGE.
- //
- //--------------------------------------------------------------------------
-
- #ifndef GuiDrawFile_h
- #define GuiDrawFile_h
-
- #include "GuiBBox.h"
- #include "swis.h"
- #include "stl:string.h"
- #include <stdlib.h>
- #include "flex_c.h"
-
- class GuiDrawFileObject
- {
- public:
- int typeId;
- size_t size;
- };
-
- class GuiDrawFileGraphicsObject : public GuiDrawFileObject
- {
- public:
- GuiBBox bounds;
- };
-
- class GuiTransform
- {
- public:
- GuiTransform() {m0=m3=(1<<16);m1=m2=m4=m5=0;}
- int m0,m1,m2,m3,m4,m5;
- };
-
- class GuiDrawFile
- {
- private:
- bool extend(size_t);
- FlexChar data;
- enum {FILE_FAILED=1,OBJECT_FAILED=2};
- public:
- GuiDrawFile(const char* programName);
- virtual ~GuiDrawFile();
- void reopen();
- _kernel_oserror* save(const char* filename);
- _kernel_oserror* render(const GuiTransform* trans=0, const GuiBBox* clip=0, bool blendFont=1) const;
- _kernel_oserror* getBBox(GuiBBox&,const GuiTransform* trans=0) const;
- _kernel_oserror* declareFonts(bool dont_download=0) const;
-
- void put(size_t i)
- {
- if (size<=capacity-sizeof(size_t) || extend(sizeof(size_t)))
- {
- ((size_t&)data.at(size))=i;
- size+=sizeof(size_t);
- }
- }
- void put(int i) {put((size_t)i);}
- void put(char c)
- {
- if (size<capacity || extend(sizeof(char))) data[size++]=c;
- }
-
- char* getPtr(int pos) {return &data.at(pos);}
- const char* getPtr(int pos) const {return &data.at(pos);}
-
- enum {npos=-1}; //invalid size_t
- size_t getSize() const {return size;}
-
- size_t startObject(size_t size); //returns position of object
- void endObject();
- void endCurrentObject();
-
- void addBBox(const GuiBBox& bbox) {
- if (bbox.xmin<bounds.xmin) bounds.xmin=bbox.xmin;
- if (bbox.xmax>bounds.xmax) bounds.xmax=bbox.xmax;
- if (bbox.ymin<bounds.ymin) bounds.ymin=bbox.ymin;
- if (bbox.ymax>bounds.ymax) bounds.ymax=bbox.ymax;
- }
- void setBBox(const GuiBBox& bbox) {bounds=bbox;}
-
- void align() {size=((size+3) &~3);}
- bool hasFailed() {return failed;}
-
- void ensureMem(unsigned int size);
-
- private:
- size_t size;
- size_t capacity;
- GuiBBox bounds;
- string programName;
- int currentObject;
- int failed;
-
- void setBBox();
- void setBBox() const;
- size_t allocate(size_t size);
- };
-
- #endif
-